import 'package:flutter/cupertino.dart';
import 'package:furaha_mkopo/commonTool/fm_route_tool.dart';
import 'package:furaha_mkopo/manager/fm_global_manager.dart';
import 'package:furaha_mkopo/page/authentication/fm_identity_auth_page.dart';
import 'package:furaha_mkopo/page/home/fm_home_detail_page.dart';
import 'package:furaha_mkopo/page/home/orderDetail/emergency/fm_emergency_page.dart';
import 'package:furaha_mkopo/page/home/orderDetail/job/fm_job_page.dart';
import 'package:furaha_mkopo/page/home/orderDetail/personal/fm_personal_page.dart';
import 'package:furaha_mkopo/page/login/fm_login_page.dart';
import 'package:furaha_mkopo/page/me/fm_me_setting_page.dart';
import 'package:furaha_mkopo/page/web/fm_web_widget.dart';
import 'package:get/get.dart';

import '../page/tab/fm_tab_controller.dart';

class FMJumpTool {

  static jumpWidget({BuildContext? context,String? url}) {
    if (url == null || url.isEmpty) return;

    if (url.startsWith("http")) {
      jumpWebWidget(context: context,url: url);
    }else if (url.contains("fms://uko.roi.n/Lady")) {
      jumpLogin(context: context);
    }else if (url.contains("fms://uko.roi.n/motionless")) {
      jumpSetting(context: context);
    }else if (url.contains("fms://uko.roi.n/voyages")) {
      jumpOrderDetail(context,url);
    }
  }

  static jumpWebWidget({BuildContext? context,String? url,String? listen,bool? isOldPage}) {

    if (url == null || url.isEmpty) return;

    final ctx = context ?? FMGlobalManager().context!;
    FMRouteTool.push(ctx, FMWebWidget(url: url,listen: listen??"",isOldPage: isOldPage));
  }

  static jumpReplaceWebWidget({BuildContext? context,String? url,String? listen}) {

    if (url == null || url.isEmpty) return;

    final ctx = context ?? FMGlobalManager().context!;
    FMRouteTool.pushReplacement(ctx, FMWebWidget(url: url,listen: listen??"",));
  }

  static jumpHomeWidget() {
    final tabController = Get.find<FMTabController>();
    tabController.jumpHome();
  }

  static jumpMeWidget() {

  }

  static jumpLogin({BuildContext? context}) {
    final ctx = context ?? FMGlobalManager().context!;
    FMRouteTool.push(ctx, const FMLoginPage());
  }

  static jumpSetting({BuildContext? context}) {
    final ctx = context ?? FMGlobalManager().context!;
    FMRouteTool.push(ctx,const FMMeSettingPage());
  }

  static jumpOrderDetail(BuildContext? context,String url) {
    final ctx = context ?? FMGlobalManager().context!;

    List<String> urlList = url.split("?");

    if (urlList.length != 2) return;

    String params = urlList.last;

    List<String> paramList = params.split("=");

    if (paramList.length != 2) return;

    FMRouteTool.push(ctx,FMHomeDetailPage(listen: paramList.last));
  }

  static void jumpAuth(BuildContext context,String tag,String? bidding,String curListen,bool replace,{bool? isOldPage = false}){
    switch (tag) {
      case "almost":
      //身份认证
        if(replace){
          FMRouteTool.pushReplacement(
              context,
              FMIdentityAuthPage(
                listen: curListen,
              ));
        }else {
          FMRouteTool.push(
              context,
              FMIdentityAuthPage(
                listen: curListen,
                isOldPage: isOldPage,
              ));
        }
        break;
      case "That":
        if(replace){
          FMRouteTool.pushReplacement(
              context,
              FMPersonalPage(
                orderId: curListen,
              ));
        }else {
          FMRouteTool.push(
              context,
              FMPersonalPage(
                orderId: curListen,
                isOldPage: isOldPage,
              ));
        }
        break;
      case "through":
        if(replace){
          FMRouteTool.pushReplacement(
              context,
              FMJobPage(
                orderId: curListen,
              ));
        }else {
          FMRouteTool.push(
              context,
              FMJobPage(
                orderId: curListen,
                isOldPage: isOldPage,
              ));
        }
        break;
      case "their":
        if(replace){
          FMRouteTool.pushReplacement(
              context,
              FMEmergencyPage(
                orderId: curListen,
              ));
        }else {
          FMRouteTool.push(
              context,
              FMEmergencyPage(
                orderId: curListen,
                isOldPage: isOldPage,
              ));
        }
        break;
      case "before":
      //银行卡信息
        if(replace){
          FMJumpTool.jumpReplaceWebWidget(
              context: context, url: bidding,listen: curListen);
        }else {
          FMJumpTool.jumpWebWidget(
              context: context, url: bidding,listen: curListen,isOldPage: isOldPage);
        }
        break;
    }
  }

}